package com.line.myprojectservice.controller;

import com.line.myprojectservice.po.Answer;
import com.line.myprojectservice.service.AnswerService;
import com.line.myprojectservice.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：Line
 * @date ： 2022/4/1 19:17
 * @description :TODO
 */
@RestController
@RequestMapping("/answer")
public class AnswerController {


    final AnswerService answerService;

    public AnswerController(AnswerService answerService) {
        this.answerService = answerService;
    }


    @PostMapping
    public ResponseUtil addMessage(@RequestBody Answer answer) {
        answerService.addAnswer(answer);
        return ResponseUtil.success();
    }

    @DeleteMapping("/{id}")
    public ResponseUtil delete(@PathVariable String id) {
        answerService.deleteAnswer(id);
        return ResponseUtil.success();
    }

    //根据帖子id查询回答
    @GetMapping("/{id}")
    public ResponseUtil queryMessageById(@PathVariable String id) {
        return ResponseUtil.success(answerService.queryAnswerById(id));
    }

}
